package com.study.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import java.util.Arrays;

/**
 * thymeleaf学习
 */
@Slf4j
@Controller
@RequestMapping("thy")
public class ThymeleafController extends SysBaseController {

    @Autowired
    private ServletContext servletContext;

    @GetMapping("hello")
    public String hello(ModelMap modelMap, HttpSession session) {

        //1 数据存入请求域
        modelMap.put("attrRequestScope", "attrRequestValueScope");
        modelMap.put("RequestScope", "attrRequestValueScopeValue2");
        //2 测试数据存入 会话域
        session.setAttribute("attrSessionScope", "学习测试");
        //3 测试数据存入 应用域
        servletContext.setAttribute("attrNameAppScope", "attrValueApppScope");

        modelMap.addAttribute("html", "<hr color=\"blue\">");
        modelMap.addAttribute("list", Arrays.asList("AA", "BB", "CC"));

        return "thy/hello";
    }

}
